package pl.druminski.robinhood.view;

import java.awt.Desktop;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URI;
import javax.swing.JOptionPane;

public class HyperLinkLabel extends HyperLinkView
{

    private String url;

    public HyperLinkLabel(String text, String url)
    {
        super(text);
        this.url = url;
        addMouseListener(new MouseAdapter()
        {

            @Override
            public void mouseClicked(MouseEvent e)
            {
                super.mouseClicked(e);
                try
                {
                    Desktop.getDesktop().browse(URI.create(HyperLinkLabel.this.getUrl()));
                } catch (IOException e1)
                {
                    JOptionPane.showMessageDialog(HyperLinkLabel.this, "Associated application not found", "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        });
    }

    public HyperLinkLabel()
    {
        this("", null);
    }

    public String getUrl()
    {
        return url == null ? "" : url;
    }

    public void setUrl(String url)
    {
        this.url = url;
    }
}
